class Solution {
    int calc_sum_of_bit_squre(int n)//此函数用来计算各个位数的平方和
    {
        int ret = 0;
        while (n) {
            int reminder = n % 10;
            ret = reminder * reminder;
            n /= 10;
        }
        return ret;
    }
public:
    bool isHappy(int n) {
        int fast =calc_sum_of_bit_squre(calc_sum_of_bit_squre(n)) ;//快指针在数列上前进两次
        int slow =calc_sum_of_bit_squre(n);//慢指针在数列上前进1次
        while (fast != slow)
        {
            fast = calc_sum_of_bit_squre(calc_sum_of_bit_squre(fast));
            slow = calc_sum_of_bit_squre(slow);
        }
        return fast == 1;
    }
};